<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @author duongbq
 * Date 2011 - 05 -11
 */
class Invoice_Detail_Model extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }
    
    private function _set_where($param = array()) {

        if (isset($param['invoice_id']))
            $this->db->where('invoice_id', $param['invoice_id']);
        
        if (isset($param['ticket_id']))
            $this->db->where('ticket_id', $param['ticket_id']);
        
        if (isset($param['quantity']))
            $this->db->where('quantity', $param['quantity']);
        
    }
    
    function insert_invoice_detail($param = array(),$getid = false){
        if(!empty($param)){
            if($this->db->insert('invoice_detail',$param)) {
                if($getid) return $this->db->insert_id();
                return true;
            }
        }
        return false;
    }

    function get_invoice_detail($param = array()) {

        $this->_set_where($param);

        if (isset($param['limit']) && isset($param['offset']))
            $this->db->limit($param['limit'], $param['offset']);

        return $this->db->get('invoice_detail')->result();
    }

    function get_invoice_detail_count($param = array()) {
        return count($this->get_invoice_detail($param));
    }

    function delete_invoice_detail($param = array()) {
        
        if(!is_array($param) || is_null($param))
            return;
        
        if (isset($param['invoice_id']))
            $this->db->where('invoice_id', $param['invoice_id']);
        
        if (isset($param['ticket_id']))
            $this->db->where('ticket_id', $param['ticket_id']);
        
        return $this->db->delete('invoice_detail');
    }
}
